const EalenToken = artifacts.require("EalenToken.sol");
const Exchange = artifacts.require("Exchange.sol");
const ETH_ADDRESS = "0x0000000000000000000000000000000000000000";

const fromWei = bn => {
    return web3.utils.fromWei(bn, "ether");
};

const toWei = number => {
    return web3.utils.toWei(number.toString(), "ether");
};

module.exports = async function (callback) {
    const token = await EalenToken.deployed();
    const exchange = await Exchange.deployed();
    const accounts = await web3.eth.getAccounts();

    // await exchange.withdrawEther(toWei(5), {
    //     from: accounts[0]
    // });

    // console.log(fromWei(await exchange.tokens(ETH_ADDRESS, accounts[0])));

    // 授权
    // await token.approve(exchange.address, toWei(100000), { from: accounts[0] });
    await exchange.withdrawToken(token.address, toWei(50000), { from: accounts[0] });
    let res = await exchange.tokens(token.address, accounts[0])
    console.log(fromWei(res));
    callback();
}